package com.yonyou.pmclouds.plan.processor;

import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.plan.entity.ScheduleItemVO;
import com.yonyou.pmclouds.plan.entity.ScheduleVO;
import com.yonyou.pmclouds.plan.rmiitf.IScheduleItemProcessor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

/**
 * @Description: 计划任务项必填项校验
 * @Author: zhangzhonghao
 * @Date: 2020-03-06
 */

@Component
public class ScheduleItemRequiredCheckProcessor implements IScheduleItemProcessor {

    @Override
    public void process(ScheduleVO scheduleVO, ScheduleItemVO rootParentItemVO, ScheduleItemVO parentItemVO,
                        ScheduleItemVO childItemVO) throws BusinessException {
        if(childItemVO != null){
            itemCheck(childItemVO);
        }

    }

    private void itemCheck(ScheduleItemVO itemVO) throws BusinessException {
        if (StringUtils.isBlank(itemVO.getName())) {
            throw new BusinessException("计划名称不能为空");
        } else if (itemVO.getName().length() > 50) {
            throw new BusinessException("计划名称长度不能超过50字");
        }
        if (itemVO.getPlanStartDate() == null || itemVO.getPlanEndDate() == null) {
            throw new BusinessException("计划开始或结束时间不能为空");
        }
    }
}
